﻿package mortal.game.view.copy.crossMainCity.panels.sub
{
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.core.*;

    public class MainCityRankList extends GSprite
    {
        private var _list:GTileList;
        private var _page:PageSelecter;
        private var _btnExitCopy:GLoadingButton;
        private var _txtScore:GTextFiled;
        private var _datas:Array;
        private var _pageNum:int = 10;
        private var _isExit:Boolean = true;

        public function MainCityRankList()
        {
            return;
        }// end function

        public function set datas(param1:Array) : void
        {
            this._datas = param1;
            this._page.maxPage = Math.ceil(this._datas.length / this._pageNum);
            this._page.currentPage = 1;
            this.updateToPage();
            return;
        }// end function

        public function set pageNum(param1:int) : void
        {
            this._pageNum = param1;
            if (this._datas != null)
            {
                this._page.maxPage = Math.ceil(this._datas.length / this._pageNum);
            }
            this._page.currentPage = 1;
            this._page.y = this._pageNum * 30.4 + 31;
            this._btnExitCopy.y = this._page.y + 38;
            this.updateToPage();
            return;
        }// end function

        public function changeToMyNamePage(param1:String) : void
        {
            return;
        }// end function

        public function updateToPage() : void
        {
            var _loc_6:MainCityBattlePlayerRankData = null;
            if (this._datas == null)
            {
                this._list.dataProvider = new DataProvider();
                this._list.drawNow();
                return;
            }
            var _loc_1:* = this._page.currentPage - 1;
            var _loc_2:* = _loc_1 * this._pageNum;
            var _loc_3:* = Math.min(_loc_2 + this._pageNum, this._datas.length);
            var _loc_4:* = new DataProvider();
            var _loc_5:* = _loc_2;
            while (_loc_5 < _loc_3)
            {
                
                _loc_6 = this._datas[_loc_5];
                if (_loc_6 != null)
                {
                    _loc_6.rank = _loc_5 + 1;
                }
                _loc_4.addItem(this._datas[_loc_5]);
                _loc_5++;
            }
            this._list.dataProvider = _loc_4;
            this._list.drawNow();
            Dispatcher.addEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            return;
        }// end function

        private function sceneUpdateHandler(param1) : void
        {
            this.checkAndSetButton();
            return;
        }// end function

        public function setScoreDesc(param1:String) : void
        {
            this._txtScore.text = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(0, 1, 790, 23, this, ImagesConst.RegionTitleBg));
            var _loc_1:* = GlobalStyle.textFormatHuang;
            _loc_1.align = TextFormatAlign.CENTER;
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20931), -18, 4, 100, 22, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20932), 74, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20933), 182, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20934), 300, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20935), 383, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20936), 465, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20937), 547, 4, 100, 22, this, _loc_1.clone()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(20938), 618, 4, 100, 22, this, _loc_1.clone()));
            this._txtScore = UIFactory.gTextField(Language.getString(20939), 691, 4, 100, 22, this, _loc_1.clone());
            this._list = UIFactory.tileList(0, 24, 770, 400, this);
            this._list.setStyle("cellRenderer", MainCityRankRender);
            this._list.rowHeight = 30.4;
            this._list.columnWidth = 768;
            this._page = UIFactory.pageSelecter(317, 320, this, PageSelecter.CompleteMode);
            this._page.configEventListener(Event.CHANGE, this.onPageChange);
            this._btnExitCopy = UIFactory.gLoadingButton(ImagesConst.ConfirmBtn_upSkin, 333, this._page.y + 38, 103, 38, this);
            this._btnExitCopy.configEventListener(MouseEvent.CLICK, this.exitHandler);
            this.checkAndSetButton();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateToPage();
            return;
        }// end function

        private function checkAndSetButton() : void
        {
            if (!CopyUtil.isInMainCityBattleFinalCopy && !CopyUtil.isInMainCityBattleKOCopy)
            {
                this._isExit = false;
                this._btnExitCopy.styleName = ImagesConst.ConfirmBtn_upSkin;
            }
            else
            {
                this._isExit = true;
                this._btnExitCopy.styleName = ImagesConst.ExitCopyBtn_upSkin;
            }
            return;
        }// end function

        private function exitHandler(event:MouseEvent) : void
        {
            if (this._isExit)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MainCityHideRankPanel));
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            Dispatcher.removeEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            this._list.dispose(param1);
            this._list = null;
            this._page.dispose(param1);
            this._page = null;
            this._btnExitCopy.dispose(param1);
            this._btnExitCopy = null;
            this._txtScore.dispose(param1);
            this._txtScore = null;
            return;
        }// end function

    }
}
